package tsg.graphic;



public class Font 
{
	//                      Style Name      Int Value    Binary Value
	public static final int PLAIN           =  0;        // 0000 0000
	public static final int BOLD            =  1;        // 0000 0001
	public static final int ITALIC          =  2;        // 0000 0010
	public static final int UNDERLINE       =  4;        // 0000 0100
	public static final int STRIKETHROUGH 	=  8;        // 0000 1000
	public static final int SUBSCRIPT       = 16;        // 0001 0000
	public static final int SUPERSCRIPT     = 32;        // 0010 0000
	                                            
	
	public static final int BOLD_ITALIC		       = BOLD   | ITALIC;
	public static final int BOLD_UNDERLINE         = BOLD   | UNDERLINE;
	public static final int BOLD_STRIKETHROUGH     = BOLD   | STRIKETHROUGH;
	public static final int BOLD_SUBSCRIPT         = BOLD   | SUBSCRIPT;
	public static final int BOLD_SUPERSCRIPT       = BOLD   | SUPERSCRIPT;
	public static final int BOLD_ITALIC_UNDERLINE  = BOLD   | ITALIC          | UNDERLINE;
	public static final int ITALIC_UNDERLINE       = ITALIC | UNDERLINE;
	public static final int ITALIC_STRIKETHROUGH   = ITALIC | STRIKETHROUGH;
	
	
	/**
	 * You can combine styles by using the bit or operator (e.g. "BOLD | ITALIC | SUBSCRIPT").
	 * 
	 * @param name
	 * @param style
	 * @param size
	 */
	public Font(String name, int style, float size)
	{
		_name  = name;
		_style = style;
		_size  = size;
		_systemFont  = FontFactory.createSystemFont(name, style, size);
	}
	
	public String getName()
	{
		return _name;
	}
	
	public int getStyle()
	{
		return _style;
	}
	
	public float getSize()
	{
		return _size;
	}
	
	public boolean getIsBold()
	{
		return (_style & BOLD) > 0;
	}
	
	public boolean getIsItalic()
	{
		return (_style & ITALIC) > 0;
	}
	
	public boolean getIsUnderline()
	{
		return (_style & UNDERLINE) > 0;
	}
	
	public boolean getIsStrikethrough()
	{
		return (_style & STRIKETHROUGH) > 0;
	}
	
	public boolean getIsSubscript()
	{
		return (_style & SUBSCRIPT) > 0;
	}
	
	public boolean getIsSuperscript()
	{
		return (_style & SUPERSCRIPT) > 0;
	}
	
	public int getStringWidth(String string)
	{
		int 	result 		= 0;
		char[] 	characters 	= string.toCharArray(); // using char array as an optimization
		
		for(int i=0; i<characters.length; i++)
		{
			result = result + _systemFont.getCharacterWidth(characters[i]);
		}
		
		return result;
	}
	
	public int getCharacterWidth(char character)
	{
		return _systemFont.getCharacterWidth(character);
	}
	
	public int getFontHeight()
	{
		return _systemFont.getFontHeight();
	}
	
	protected SystemFont getSystemFont()
	{
		return _systemFont;
	}
	
	private float  		_size   		= 10.0f;
	private SystemFont 	_systemFont 	= null;
	private int    		_style  		= PLAIN;
	private String 		_name   = null;
}
